# SPDX-License-Identifier: GPL-3.0-or-later
#!/bin/sh
set -e

wget https://gitlab.com/libeigen/eigen/-/archive/3.3.7/eigen-3.3.7.zip
unzip eigen-3.3.7.zip
mkdir -p eigen-3.3.7/build
cd eigen-3.3.7/build
cmake ..
make
sudo make install
cd ../..
rm -rf eigen-3.3.7.zip eigen-3.3.7
mkdir -p old_eigen_backup
cp /usr/lib/cmake/eigen3/*.cmake old_eigen_backup/
sudo cp /usr/local/share/eigen3/cmake/*.cmake /usr/lib/cmake/eigen3/

mkdir -p autoware.ai/src
cd autoware.ai

wget -O autoware.ai.repos "https://ghproxy.com/raw.githubusercontent.com/autowarefoundation/autoware.ai/1.14.0/autoware.ai.repos"
vcs import src < autoware.ai.repos

rosdep update
rosdep install -y --from-paths src --ignore-src --rosdistro $ROS_DISTRO

MAKEFLAGS="-j 4" AUTOWARE_COMPILE_WITH_CUDA=1 colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release --executor sequential
sudo cp ../old_eigen_backup/*.cmake /usr/lib/cmake/eigen3/
